package com.dimld.utils;

import java.security.MessageDigest;

class MD5Util {

    private static String getMD5(String message) {
        String md5str = "";
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");

            byte[] input = message.getBytes();

            byte[] buff = md.digest(input);

            md5str = bytesToHex(buff);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return md5str.toLowerCase();
    }

    private static String bytesToHex(byte[] bytes) {
        StringBuilder md5str = new StringBuilder();

        for (byte aByte : bytes) {
            int digital = aByte;

            if (digital < 0) {
                digital += 256;
            }
            if (digital < 16) {
                md5str.append("0");
            }
            md5str.append(Integer.toHexString(digital));
        }
        return md5str.toString().toUpperCase();
    }
}